package com.koron.sinoprobe.web.subpackage.controller;

import com.koron.bean.base.Response;
import com.koron.common.core.config.ThreadLocalContext;
import com.koron.sinoprobe.web.subpackage.bean.dto.SubPackageDetailDTO;
import com.koron.sinoprobe.web.subpackage.service.SubPackageDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "分包明细")
@RequestMapping("/subPackage/detail")
@RestController
public class SubPackageDetailController {

    @Autowired
    private SubPackageDetailService subPackageDetailService;

    public String getCurrDs(){
        return ThreadLocalContext.get().getCurrDs();
    }

    @ApiOperation(value = "新增分包明细")
    @PostMapping("/save")
    public Response addSubPackageDetail(@RequestBody SubPackageDetailDTO subPackageDetailDTO) {
        return Response.ok(ADOConnection.runTask(getCurrDs(),subPackageDetailService,"addSubPackageDetail", SubPackageDetailDTO.class, subPackageDetailDTO));
    }

    @ApiOperation(value = "新增分包明细")
    @PostMapping("/batchSave")
    public Response batchSave(@RequestBody List<SubPackageDetailDTO> list) {
        return Response.ok(ADOConnection.runTask(getCurrDs(),subPackageDetailService,"batchSave", List.class, list));
    }

    @ApiOperation(value = "根据施工分包id获取分包明细")
    @GetMapping("/getByPackageId")
    public Response getSubPackageDetailByPackageId(@RequestParam("packageId") String packageId) {
        return Response.ok(ADOConnection.runTask(getCurrDs(),subPackageDetailService,"getSubPackageDetailByPackageId", List.class, packageId));
    }

    @ApiOperation(value = "根据施工分包id获取分包明细")
    @GetMapping("/getById")
    public Response getSubPackageDetailById(@RequestParam("id") String id) {
        return Response.ok(ADOConnection.runTask(getCurrDs(),subPackageDetailService,"getSubPackageDetailById", SubPackageDetailDTO.class, id));
    }

    @ApiOperation(value = "更新分包明细")
    @PostMapping("/update")
    public Response updateSubPackageDetail(@RequestBody SubPackageDetailDTO subPackageDetailDTO) {
        return Response.ok(ADOConnection.runTask(getCurrDs(),subPackageDetailService,"updateSubPackageDetail", SubPackageDetailDTO.class, subPackageDetailDTO));
    }

    @ApiOperation(value = "根据id删除分包明细")
    @GetMapping("/delete")
    public Response deleteSubPackageDetail(@RequestParam("id") String id) {
        return Response.ok(ADOConnection.runTask(getCurrDs(),subPackageDetailService,"deleteSubPackageDetail", Integer.class, id));
    }
}
